import {Component, OnInit} from '@angular/core';
import {B2bService} from '../b2b.service';

@Component({
  selector: 'app-order-statistics',
  templateUrl: './order-statistics.component.html',
  styleUrls: ['./order-statistics.component.scss']
})
export class OrderStatisticsComponent implements OnInit {
  query = {
    payTime: [],
    shipTime: [],
    createTime: [],
    page: 1,
    pageSize: 10,
  };
  listOfData = {
    records: [],
    total: 100,
  };

  constructor(
    public b2bService: B2bService,
  ) {
  }

  ngOnInit(): void {
    this.getTableData();
  }


  onPageIndexChange(index: number) {
    this.query.page = index;
    this.getTableData();
  }

  onPageSizeChange(pageSize: number) {
    this.query.pageSize = pageSize;
    this.getTableData();
  }

  getTableData() {
    this.listOfData.records = [];
    this.b2bService.getOrderStatisticsList({
      payBeginTime: this.b2bService.formatTime(this.query.payTime[0], 'date'), // 付款开始时间
      payEndTime: this.b2bService.formatTime(this.query.payTime[1], 'date'), // 付款结束
      shipBeginTime: this.b2bService.formatTime(this.query.shipTime[0], 'date'), // 发货开始时间
      shipEndTime: this.b2bService.formatTime(this.query.shipTime[1], 'date'), // 发货结束时间
      createBeginTime: this.b2bService.formatTime(this.query.createTime[0], 'date'), // 下单开始时间
      createEndTime: this.b2bService.formatTime(this.query.createTime[1], 'date'), // 下单结束时间
      page: this.query.page,
      pageSize: this.query.pageSize,
    }).then((res: any) => {
      if (res.code === 0) {
        this.listOfData = res.data;
      }
    });
  }

  queryBtn() {
    this.query.page = 1;
    this.getTableData();
  }

  resetCondition() {
    this.query = {
      payTime: [],
      shipTime: [],
      createTime: [],
      page: 1,
      pageSize: 10,
    };
    this.getTableData();
  }
}
